//
//  User.m
//  Fangmm
//
//  Created by 阮琦 on 16/3/14.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "User.h"

@implementation User

static User *_user;

+ (User *)allocWithZone:(struct _NSZone *)zone
{
    @synchronized(self) {
        if (_user == nil) {
            _user = [super allocWithZone:zone];
        }
    }
    return _user;
}

+ (User *)sharedUser{
    @synchronized(self){
        if(_user == nil){
            _user = [[self alloc] init];
            _user.name = @"未完善";
            _user.constellation = @"未完善";
            _user.country = @"未完善";
            _user.province = @"未完善";
            _user.city = @"未完善";
            _user.industry = @"未完善";
            _user.profession = @"未完善";
            _user.ageGroup = 90;
        }
    }
    return _user;
}

-(User *)copyWithZone:(struct _NSZone *)zone{
    return _user;
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    NSLog(@"key = %@",key);
}

-(void)encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeObject:self.userId forKey:@"userId"];
    [encoder encodeObject:self.name forKey:@"name"];
    [encoder encodeObject:self.avatar forKey:@"avatar"];
    [encoder encodeObject:self.mobile forKey:@"mobile"];
    [encoder encodeObject:self.gender forKey:@"gender"];
    [encoder encodeObject:self.constellation forKey:@"constellation"];
    [encoder encodeInt:self.ageGroup forKey:@"ageGroup"];
    [encoder encodeObject:self.country forKey:@"country"];
    [encoder encodeObject:self.province forKey:@"province"];
    [encoder encodeObject:self.city forKey:@"city"];
    [encoder encodeObject:self.industry forKey:@"industry"];
    [encoder encodeObject:self.companyMail forKey:@"companyMail"];
    [encoder encodeObject:self.profession forKey:@"profession"];
    [encoder encodeObject:self.fullName forKey:@"fullName"];
    [encoder encodeObject:self.identityCard forKey:@"identityCard"];
    [encoder encodeBool:self.certification forKey:@"certification"];
    [encoder encodeBool:self.enterpriseAuth forKey:@"enterpriseAuth"];
    [encoder encodeObject:self.tags forKey:@"tags"];
}

#pragma mark 从文件中读取
-(id)initWithCoder:(NSCoder *)decoder{
    self.userId = [decoder decodeObjectForKey:@"userId"];
    self.name = [decoder decodeObjectForKey:@"name"];
    self.avatar = [decoder decodeObjectForKey:@"avatar"];
    self.mobile = [decoder decodeObjectForKey:@"mobile"];
    self.gender = [decoder decodeObjectForKey:@"gender"];
    self.constellation = [decoder decodeObjectForKey:@"constellation"];
    self.ageGroup = [decoder decodeIntForKey:@"ageGroup"];
    self.country = [decoder decodeObjectForKey:@"country"];
    self.province = [decoder decodeObjectForKey:@"province"];
    self.city = [decoder decodeObjectForKey:@"city"];
    self.industry = [decoder decodeObjectForKey:@"industry"];
    self.companyMail = [decoder decodeObjectForKey:@"companyMail"];
    self.profession = [decoder decodeObjectForKey:@"profession"];
    self.fullName = [decoder decodeObjectForKey:@"fullName"];
    self.identityCard = [decoder decodeObjectForKey:@"identityCard"];
    self.certification = [decoder decodeBoolForKey:@"certification"];
    self.enterpriseAuth = [decoder decodeBoolForKey:@"enterpriseAuth"];
    self.tags = [decoder decodeObjectForKey:@"tags"];
    return self;
}


@end
